﻿using CraftParameterConfig.Domain.Interfaces;
using CraftParameterConfig.Infrastructure.Data;
using CraftParameterConfig.Services.Data;
using CraftParameterConfig.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CraftParameterConfig.Infrastructure.Common
{
    public static class ObjectFactory
    {
        public static object GetObject(string interfaceName)
        {
            switch (interfaceName)
            {
                case "ITableNameService":
                    return new TableNameService(GetObject("ITableNameRespository") as ITableNameRespository);
                case "ITableNameRespository":
                    return new TableNameRespository(GetObject("IUnitOfWork") as IUnitOfWork);
                case "IUnitOfWork":
                    return new UnitOfWork();
                case "ITableNameAuth":
                    return new TableNameAuth();
                case "ILogInfo":
                    return new LogInfo();
                case "ITableIndexRespository":
                    return new TableIndexRespository(GetObject("IUnitOfWork") as IUnitOfWork);
                case "ITableDataRespository":
                    return new TableDataRespository(GetObject("IUnitOfWork") as IUnitOfWork);
                case "ITableFieldService":
                    var t1 = GetObject("ITableNameRespository") as ITableNameRespository;
                    var t2 = GetObject("ITableIndexRespository") as ITableIndexRespository;
                    var t3 = GetObject("ITableDataRespository") as ITableDataRespository;
                    return new TableFieldService(t1, t2, t3);
                case "ITableFieldAuth":
                    return new TableFieldAuth();
                case "IParameterAccessRespository":
                    return new ParameterAccessRespository(GetObject("IUnitOfWork") as IUnitOfWork);
                case "IParameterDataRespository":
                    return new ParameterDataRespository(GetObject("IUnitOfWork") as IUnitOfWork);
                case "IParameterIndexRespository":
                    return new ParameterIndexRespository(GetObject("IUnitOfWork") as IUnitOfWork);
                case "IParameterService":
                    var t4 = GetObject("ITableNameRespository") as ITableNameRespository;
                    var t5 = GetObject("ITableIndexRespository") as ITableIndexRespository;
                    var t6 = GetObject("ITableDataRespository") as ITableDataRespository;
                    var t7 = GetObject("IParameterAccessRespository") as IParameterAccessRespository;
                    var t8 = GetObject("IParameterIndexRespository") as IParameterIndexRespository;
                    var t9 = GetObject("IParameterDataRespository") as IParameterDataRespository;
                    return new ParameterService(t4, t5, t6, t7, t8, t9);
                case "IParameterAuth":
                    return new ParameterAuth();
                default:
                    return null;
            }
        }
    }
}
